package com.etennis.controller;
import com.etennis.pojos.PageResult;
import com.etennis.pojos.ResponseResult;
import com.etennis.pojos.dto.web.MemberDTO;
import com.etennis.pojos.dto.web.MemberPageQueryDTO;
import com.etennis.pojos.vo.web.GroupCountVO;
import com.etennis.pojos.vo.web.GroupMVPVO;
import com.etennis.pojos.vo.web.MemberVO;
import com.etennis.service.IMemberService;
import com.etennis.service.ISeasonInfoService;
import com.etennis.utils.RedisCache;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/web/member")
@Slf4j
@Api(tags = "网页端-会员管理接口")
public class MemberController {
    @Autowired
    IMemberService iMemberService;
    @Autowired
    private RedisCache redisCache;
    @Autowired
    ISeasonInfoService iSeasonInfoService;


//    @PostMapping("/test")
//    public ResponseResult test(){
//        Member member=new Member();
//        member.setName("haha");
//        member.setAccount("account");
//        member.setPassword("pass");
//        member.setIcon("icon");
//        iMemberService.save(member);
//        return ResponseResult.okResult();
//    }


    @GetMapping("/mvp")
    @ApiOperation("查询各组mvp")
    public ResponseResult<GroupMVPVO> groupMVP(){
        GroupMVPVO groupMVPVO=iMemberService.groupMVP();
        return ResponseResult.okResult(groupMVPVO);
    }

    @GetMapping("/group")
    @ApiOperation("会员成分分布")
    public ResponseResult<GroupCountVO> groupCount(){
        GroupCountVO res = iSeasonInfoService.groupCount();
        return ResponseResult.okResult(res);
    }

    @PostMapping("/save")
    @ApiOperation("新增会员")
    public ResponseResult save(@RequestBody MemberDTO memberDTO){
        iMemberService.saveMember(memberDTO);
        return ResponseResult.okResult();
    }

    @PutMapping("/update")
    @ApiOperation("修改会员")
    public ResponseResult update(@RequestBody MemberDTO memberDTO){
        iMemberService.updateMember(memberDTO);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除会员")
    public ResponseResult delete(@PathVariable Long id){
        iMemberService.deleteMember(id);
        return ResponseResult.okResult();
    }

    @GetMapping("/page")
    @ApiOperation("分页展示会员")
    public ResponseResult<PageResult<MemberVO>> page(MemberPageQueryDTO memberPageQueryDTO){
        PageResult<MemberVO> page = iMemberService.pageMember(memberPageQueryDTO);
        return ResponseResult.okResult(page);
    }


}
